package com.example.web_chat.controller;

import com.example.web_chat.model.Result;
import com.example.web_chat.model.User;
import com.example.web_chat.service.UserService;
import jdk.nashorn.internal.ir.RuntimeNode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    UserService userService;

    // 用户登录
    @RequestMapping("/login")
    public Result login(String username, String password, HttpServletRequest request) {
        log.info("登录接口，username:{}", username);
        log.info("登录接口，password:{}", password);
        //用户验证逻辑
        return userService.loginLogic(username, password, request);
    }

    //用户注册
    @RequestMapping("/register")
    public Result register(String username, String password) {
        log.info("注册接口，username:{}", username);
        log.info("注册接口，password:{}", password);
        return userService.registerLogic(username, password);
    }

    //获取当前登录用户名
    @RequestMapping("/userInfo")
    public Result getUser(HttpServletRequest request) {
        return userService.getUserInfo(request);
    }

    //获取好友列表
    @RequestMapping("/getFriend")
    public Result getFriend(HttpServletRequest request) {
        return userService.getFriendLogic(request);
    }

    //获取会话列表
    @RequestMapping("/getMessageSession")
    public Result getMessageSession(HttpServletRequest request) {
       return userService.getSessionLogic(request);
    }


    //新增会话
    @RequestMapping("/createSession")
    public Result createSession(Integer friendId, HttpServletRequest request) {
       return userService.createSessionLogic(friendId, request);
    }

    //获取当前会话中的所有消息
    @RequestMapping("/getAllMessage")
    public Result getAllMessage(Integer sessionId) {
        return userService.getMessageLogic(sessionId);
    }


}
